<template>
  <!--出刀查询-->
  <component :is="cfg.comp.ckdao" />

  <n-layout
    has-sider
    class="v1_body"
    style="height: 100vh"
    :native-scrollbar="false"
    v-if="$set.mb == false"
  >
    <n-layout-header style="height: 64px" bordered>
      <component :is="comp.header" />
    </n-layout-header>
    <n-layout position="absolute" style="top: 64px; bottom: 35px" has-sider>
      <n-layout :native-scrollbar="false">
        <div class="v0_body">
          <!--载入背景图-->
          <div class="bgimg">
            <div class="bgimg3"></div>
          </div>
          <div class="v2_body bdw" style="padding-top: 8px">
            <div class="content bgc" :class="cfg.app.baseclass">
              <router-view />
            </div>
          </div>
        </div>
      </n-layout>
    </n-layout>
    <n-layout-footer position="absolute" style="height: 35px" bordered>
      <div style="margin-top: 6px; text-align: center">
        火焰猫燐 > 坎公工具站 Ver.{{ cfg.ver }} 　|　<a
          _target="_blank"
          href="https://beian.miit.gov.cn/#/Integrated/index"
          >{{ cfg.icp }}</a
        >
      </div>
    </n-layout-footer>
  </n-layout>
  <template v-else>
    <component :is="comp.header" />
    <div class="bgimg">
      <div class="bgimg3"></div>
    </div>
    <div>
      <div class="v1_body">
        <div class="v0_body">
          <div class="v2_body bdw pdx1 bgc">
            <div class="content" :class="cfg.app.baseclass">
              <router-view />
            </div>
          </div>
        </div>
      </div>
      <van-tabbar
        class="bottom_tab"
        route
        :placeholder="true"
        :safe-area-inset-bottom="true"
      >
        <template v-for="item in cfg.lv2tab">
          <template v-if="ct.qxpd(item) == true">
            <van-tabbar-item
              :to="{
                name: item.name,
                params: item.params ?? [],
              }"
            >
              <span>{{ item.title }} </span>
              <template #icon="props">
                <n-icon size="20" :component="item?.icon" />
              </template>
            </van-tabbar-item>
          </template>
        </template>
      </van-tabbar>
    </div>
  </template>
</template>

<script>
import { cfg } from "@/cfg/cfg.js";
import header from "@/views/sys/header.vue";
import new_model from "@/comp/new_modal.vue";
import { getuser } from "@/cfg/function.js";

export default defineComponent({
  setup() {
    cfg.upd_diy("init");
    let ct = {
      qxpd: (item) => {
        const user = cfg.user;

        if (item.mobile == true) {
          if (cfg.mobile == true) {
            return true;
          } else {
            return false;
          }
        }
        if (user?.group?.admin == true) {
          return true;
        }
        if (item.bz == true) {
          if (user?.group?.Introduction == true) {
            return true;
          } else {
            return false;
          }
        }
        if (item.login == true) {
          if (user?.uid?.length >= 1) {
            return true;
          } else {
            return false;
          }
        }
        return true;
      },
    };

    cfg.jsb = false;
    cfg.model = new_model;

    cfg.comp = {
      login: defineAsyncComponent(() => import("@/comp/m_login.vue")),
      ckdao: defineAsyncComponent(() => import("@/comp/ckdao.vue")),
    };

    if (cfg.mobile == true) {
      cfg.sizebtn = "small";
    } else {
      cfg.sizebtn = "";
    }

    //加载该文件的时间
    cfg.loadtime = new Date().getTime();

    cfg.login_uuid = localStorage.getItem("login_uuid");
    cfg.login_stat = localStorage.getItem("login_stat");
    cfg.diy_img_bnpx = localStorage.getItem("diy_img_bnpx") ?? 0.65;
    cfg.qypx = localStorage.getItem("qypx") ?? "1200px";

    const comp = { header };
    cfg.function.uproutename = (name, type, val) => {
      let arr = {};
      arr[type] = val;
    };
    ct.updateWidth = () => {
      const layBodyElement = document?.querySelector(".v2_body");
      cfg.sswd = layBodyElement?.offsetWidth;
    };

    //内容区域大小
    ct.qypx = (v) => {
      cfg.qypx = v;
      localStorage.setItem("qypx", v);
      return;
    };
    cfg.qy = ct.qypx;
    // 获取主题缓存

    cfg.updateWidth = ct.updateWidth;

    ct.upd_info = () => {
      getuser();
    };
    onMounted(async () => {
      await getuser();
      window.addEventListener("resize", ct.updateWidth);
      cfg.run = true;
      cfg.run0 = true;
      nextTick(() => {
        //每秒循环
        setInterval(() => {
          ct.updateWidth();
        }, 1000);
        ct.updateWidth();
      });

      //监听全局电脑/手机点击操作
      window.removeEventListener("click", () => {});
      window.addEventListener("click", () => {
        const timer = new Date().getTime();
        if (timer - cfg.loadtime >= 60 * 60 * 1000) {
          cfg.loadtime = new Date().getTime();
          ct.upd_info();
        }
      });
    });

    return {
      cfg,
      ct,
      comp,
    };
  },
});
</script>
